#pragma once
#include "qsyncobject.h"


namespace micro
{
namespace core
{

class QSemaphore: public QSyncObject
{

public:

	QSemaphore(  long initialCount, long maxCount, const TCHAR * name = nullptr, LPSECURITY_ATTRIBUTES sa = nullptr );
    ~QSemaphore();
	


    virtual bool Unlock()
    {
        ASSERT( m_hHandle );
        return release( 1, 0 );
    }
    
	virtual bool Lock()
    {
        return false;
    }
	

    bool release( long releaseCount, long * prevCount )
    {
        BOOL rc = FALSE;

        if ( m_hHandle )
        {
            rc = ::ReleaseSemaphore( m_hHandle, releaseCount, prevCount );
        }

        return ( 0 != rc );
    }


    bool wait( DWORD milliSecond )
    {
        return QSyncObject::Lock( milliSecond );
    }

};

}
}